<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Promise</title>
</head>
<script>
    //promise是ES6中一个异步编程的构造函数,用来封装异步操作,
    //可以获取其成功失败的结果。
    const p = new Promise(function(resolve,reject) {
        setTimeout(() => {
            let data = '数据库中用户数据'
            resolve(data)
        }, 1000);
    })
    p.then(function(value) {
        console.log(value)
    },function(reason) {})

    const p2 = new Promise(function(resolve,reject) {
        setTimeout(() => {
            let err = '访问失败了'
            reject(err)
        }, 1000);
    })
    p2.then(function(value) {},function(reason) {
        console.log(reason)
    })
</script>
</html>